﻿using Client.Common.Extensions;
using Client.Todo.Common.Models;
using Prism.Commands;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client.Todo.ViewModels
{
    /// <summary>
    /// 设置VM
    /// </summary>
    public class SettingsViewModel : ViewModelBase
    {
        private readonly IRegionManager _regionManager;

        /// <summary>
        /// 注入IRegionManaer的构造函数
        /// </summary>
        public SettingsViewModel(IRegionManager regionManager):this()
        {
            _regionManager = regionManager;
        }

        public SettingsViewModel() 
        {
            CreateMenuBars();
        }



        #region 导航

        /// <summary>
        /// 导航 - 命令
        /// </summary>
        private DelegateCommand<MenuBar> _navigateCmd;

        /// <summary>
        /// 导航 - 命令
        /// </summary>
        public DelegateCommand<MenuBar> NavigateCmd =>
            _navigateCmd ?? (_navigateCmd = new DelegateCommand<MenuBar>(ExecuteNavigate));

        /// <summary>
        /// 执行 - 导航
        /// </summary>    
        void ExecuteNavigate(MenuBar parameter)
        {
            if (parameter != null && !string.IsNullOrEmpty(parameter?.NameSpace))
            {
                _regionManager?.Regions[PrismManager.SettingsViewRegionName]?.RequestNavigate(parameter.NameSpace);
            }
        }

        #endregion 导航

        #region 菜单列表

        /// <summary>
        /// 菜单列表
        /// </summary>
        private ObservableCollection<MenuBar> _menuBars;

        /// <summary>
        /// 菜单列表
        /// </summary>
        public ObservableCollection<MenuBar> MenuBars
        {
            get { return _menuBars; }
            set { SetProperty(ref _menuBars, value); }
        }

        #endregion 菜单列表 

        /// <summary>
        /// 创建菜单栏
        /// </summary>
        void CreateMenuBars()
        {
            MenuBars = new ObservableCollection<MenuBar>();
            MenuBars.Add(new MenuBar()
            {
                Icon = "Palette",
                Title = "个性化",
                NameSpace = "SkinView",
            });

            MenuBars.Add(new MenuBar()
            {
                Icon = "CogOutline",
                Title = "系统设置",
                NameSpace = "SystemSettingsView",
            });
            MenuBars.Add(new MenuBar()
            {
                Icon = "InformationOutline",
                Title = "关于",
                NameSpace = "AboutView",
            });
        }
    }
}
